<?php
/**
 * Created by PhpStorm.
 * User: HKHome
 * Date: 15-2-12
 * Time: 下午11:54
 */

namespace Home\Controller;

use Think\Controller;

class ContentController extends Controller{

    public function newsList(){
        $cate_db = M('category');
        $cate_map['catname'] = array('eq','首页公告栏');
        $catelist = $cate_db->where($cate_map)->select();
        if(sizeof($catelist)==0){
            echo '无公告';
        }else{
            $new_db = M('news');
            $news_map['status'] = array('eq',1);
            $news_map['catid'] = array('eq',$catelist[0]['catid']);
            $newlist = $new_db->field(array('id','title'))->where($news_map)->select();
            //dump($new_db->getLastSql());
            //$this->ajaxReturn($newlist);
            //$this->success('获取成功',$newlist);
            $this->ajaxReturn($newlist);
        }
    }
    public function getNewsInfo($id){
        $new_db = M('news');
        $news_map['status'] = array('eq',1);
        $news_map['id'] = array('eq',$id);
        $newlist = $new_db->field(array('content','title'))->where($news_map)->select();
        if(sizeof($newlist)==1){
            $this->assign('content',$newlist[0]['content']);
            $this->assign('title',$newlist[0]['title']);
        }else{
            $this->assign('content','');
            $this->assign('title','您查询的公告不存在');
        }
        $this->theme('PC')->display('Content/news_detail');
    }

     public function bannerList(){
         $cate_db = M('category');
         $cate_map['catname'] = array('eq','首页Banner');
         $catelist = $cate_db->where($cate_map)->select();
         if(sizeof($catelist)==0){
             $this->error('无公告');
         }else{
             $new_db = M('news');
             $news_map['status'] = array('eq',1);
             $news_map['catid'] = array('eq',$catelist[0]['catid']);
             $newlist = $new_db->field(array('id','title','thumb','url'))->where($news_map)->select();
             //dump($new_db->getLastSql());
             //$this->ajaxReturn($newlist);
             $this->success('获取成功',$newlist);
        }
     }
} 